/*
 * @Author: lin_zizhuo 2297304135@qq.com
 * @Date: 2023-11-27 08:49:11
 * @LastEditors: lin_zizhuo 2297304135@qq.com
 * @LastEditTime: 2023-11-27 08:53:14
 * @FilePath: /signal_text/signal_produce/text_alarm.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <unistd.h>
#include <signal.h>
using namespace std;


void myhandler(int signo)
{
    cout << "I get a sig: " << signo << endl;
    alarm(5);
}

// 通过实验发现，进程中只能存在一个时钟，后面的时钟会覆盖后面的时钟

int main()
{
    signal(14, myhandler);
    
    unsigned int  n = alarm(5);
    sleep(2);
    n = alarm(5);
    cout << n << endl;
    while(true)
    {
        cout << "I' m running!" << endl;
        sleep(1);
    }
    return 0;
}